package com.idealighter.game.roomcard.struct;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.idealighter.game.server.db.datadb.generate.domain.RoomCardGameCfgDomain;
import com.idealighter.utils.check.EmptyUtil;
import java.util.concurrent.atomic.AtomicInteger;

public class RoomCardGameCfg<C extends RoomCardGameCfgValue> extends RoomCardGameCfgDomain {
  private static final long serialVersionUID = 2918619833165668700L;
  // private TypeReference<C> CFG_VALUE_TYPE = new TypeReference<C>() {};
  private final TypeReference<C> cfgValueType;
  // 版本
  private AtomicInteger version = new AtomicInteger(0);

  public RoomCardGameCfg(TypeReference<C> cfgValueRefer) {
    this.cfgValueType = cfgValueRefer;
  }

  /**
   * @Title cfgs.
   * @Description 返回配置信息
   * @date 2018年6月13日 下午4:55:12
   * @return .
   */
  public C cfgs() {
    C result = null;
    if (EmptyUtil.stringIsNotEmpty(this.getGameCfgs())) {
      result = JSON.parseObject(this.getGameCfgs(), cfgValueType);
    }
    return result;
  }

  @Override
  public Integer getVersion() {
    return this.version.get();
  }

  @Override
  public void setVersion(Integer version) {
    this.version.set(version);
  }

  public long incVersion() {
    return this.version.incrementAndGet();
  }
}
